import fs from 'fs'
import path from 'path'

import axios from 'axios'
import dayjs from 'dayjs'

import { getExtName, getBaseName, compressDir } from '@/utils'
import { compressVideo } from './utils/video'
import { mixingVideoAudio } from './utils/video'

async function handler() {

  console.log('Hello TypeScript !')

  // 获取文件名、扩展名
  console.log(getExtName('C:\\Users\\dyna\\Desktop\\cli.txt'))
  console.log(getBaseName('C:\\Users\\dyna\\Desktop\\cli.txt'))

  // 压缩视频文件
  const sourceFilePath = 'C:\\Users\\tiga\\Desktop\\1.mp4'
  const outFilePath = 'C:\\Users\\tiga\\Desktop\\2.mp4'
  if (fs.existsSync(sourceFilePath)) {
    await compressVideo(sourceFilePath, outFilePath, (params: { progress: number }) => {
      console.log(params.progress + '%')
    })
  }

  // 视频音频混流
  const sourceVideoPath = 'C:\\Users\\tiga\\Desktop\\111\\video.m4s'
  const sourceAudioPath = 'C:\\Users\\tiga\\Desktop\\111\\audio.m4s'
  const outMixingFilePath = 'C:\\Users\\tiga\\Desktop\\111\\merge.mp4'
  if (fs.existsSync(sourceVideoPath) && fs.existsSync(sourceAudioPath)) {
    mixingVideoAudio({
      sourceVideoPath,
      sourceAudioPath,
      outFilePath: outMixingFilePath
    }, params => {
      console.log(params.progress + '%')
    })
  }

  // 压缩文件 
  compressDir('./node_modules', './node_modules.zip').then(() => {
    console.log('压缩完成')
  })

}

handler()